<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html dir="rtl">
	<head>
		<title>testing Core HTML/DOM/CSS/Style utils</title>
		<style type="text/css">
			@import "../../resources/dojo.css";
		</style>
		<script type="text/javascript" 
			src="../../dojo.js" 
			djConfig="isDebug: true"></script>
		<script type="text/javascript">
			dojo.require("doh.runner");
			
			dojo.addOnLoad(function(){
				doh.register("t", 
					[
						function coordsWithVertScrollbar(t){
							// show vertical scrollbar
							dojo.byId("rect_vert").style.display = "";
							scrollTo(0, 50);
							var d = new doh.Deferred();
							setTimeout(function(){ // need time to render
								try{
									t.is(100, dojo.position('rect100').x, "x pos should be 100 after vertical scroll");
									t.is(50, dojo.position('rect100').y, "y pos should be 50 after vertical scroll");
									d.callback(true);
								}catch(e){
									d.errback(e);
								}finally{
									dojo.byId("rect_vert").style.display = "none";
								}
							}, 100);
							return d;
						},

						function coordsWithHorzScrollbar(t){
							// show horizonal scrollbar & scroll a bit left
							dojo.byId("rect_horz").style.display = "";
							scrollTo(0, 0);
							var d = new doh.Deferred();
							setTimeout(function(){ // need time to render
								try{
									var pos = dojo.position('rect100');
									t.is(100, pos.y, "position().y="+pos.y+" but should be 100 after horizontal scroll");
									scrollBy(100, 0); // funny scrolling to account for different browsers
									scrollBy(-50, 0);
									t.is(50, Math.abs(dojo.position('rect100').x-pos.x), "position().x should have changed by 50 after horizontal scroll (actual change was " + Math.abs(dojo.position('rect100').x-pos.x) + ")");
									scrollTo(0, 0); // reset horizontal scroll before hiding scrollbar for IE8's benefit
									d.callback(true);
								}catch(e){
									d.errback(e);
								}finally{
									dojo.byId("rect_horz").style.display = "none";
								}
							}, 100);
							return d;
						},

						function eventClientXY(t){ // IE only test
							if(dojo.isIE){
								// show vertical scrollbar
								dojo.byId("rect_vert").style.display = "";

								var rect = dojo.byId("rect100");
								var assertException = null;

								function rect_onclick(e){
									// move the rectangle to the mouse point
									rect.style.left = e.pageX + "px";
									rect.style.top = e.pageY + "px";
									window.alert("Do NOT move your mouse!!!\n\n" + 
												"The black rectangle's top-left point should be under the mouse point.\n\n" +
												"If not, you will see a failure in the test report later.\n\n" +
												"Now press the space bar, but do NOT move your mouse.");
									rect.fireEvent('ondblclick');
								}

								function rect_ondblclick(){
									// test if the rectangle is really under the mouse point
									try{
										t.is(0, event.offsetX);
										t.is(0, event.offsetY);
									}catch(e){ // allow the exception in a event handler go to the event firer 
										assertException = e;
									}
								}

								dojo.connect(rect, "onclick", null, rect_onclick);
								dojo.connect(rect, "ondblclick", null, rect_ondblclick);
								window.alert("Move the mouse to anywhere in this page, and then press the space bar.");
								rect.fireEvent('onclick');
								if(assertException != null){
									throw assertException;
								}
							}
						},
						function testScrolledPosition(t){
							doh.t(dojo.byId("scrollingStrictIframe").testResult, "scrolled strict position");
							doh.t(dojo.byId("scrollingQuirksIframe").testResult, "scrolled quirks position");
						}
						
					]
				);
				doh.run();
			});
		</script>
		<style type="text/css">
			#rect100 {
				background-color: black;
				color: white;
				position: absolute;
				left: 100px;
				top: 100px;
				width: 100px;
				height: 100px;
				border: 0px;
				padding: 0px;
				margin: 0px;
				overflow: hidden;
			}
		</style>
	</head>
	<body>
		<h1>testing Core HTML/DOM/CSS/Style utils</h1>
		<div id="rect100">
			100px rect, abs, 
			mouse point is at top-left after the test "eventClientXY"
		</div>
		<div id="rect_vert" style="height:1600px;display:none">show vertical scrollbar</div>
		<div id="rect_horz" style="width:1600px;position:relative;right:-200px;display:none">show horizonal scrollbar</div>
		<br>
		<iframe id="scrollingStrictIframe" src="scrollingStrictIframe.html?rtl"></iframe>
		<iframe id="scrollingQuirksIframe" src="scrollingQuirksIframe.html?rtl"></iframe>
	</body>
</html>

